home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu453.dms
/
pu453.adf
/
extras
/
basic_sources
/
checkers2.3.bas
< prev
next >
Wrap
BASIC Source File
|
1992-11-08
|
28KB
|
1,412 lines
REM ------- Checkers v2.3 ** ATTACKER ** ------------
REM $option Y+,K200
RANDOMIZE TIMER
SCREEN 1,640,512,2,4
WINDOW 1,"",(0,0)-(600,480),0,1
PALETTE 0,0,0,0
PALETTE 1,.7,.7,.7
PALETTE 2,1,0,0
PALETTE 3,0,0,1
sxs = 1 : sxe = 600
sys = 1 : sye = 380
eatf = 0
DIM a(8,8)
DIM a2(8,8)
setpieces a()
WHILE MOUSE(0)=0
update a(),sxs,sys,sxe,sye
play a(),-1,a2()
makekings a(),0
update a(),sxs,sys,sxe,sye
play2 a(),1,a2()
makekings a(),0
WEND
WHILE MOUSE(0) = 0 : WEND
SYSTEM
SUB play(a(),col,n()) STATIC
SHARED sxs,sys,sxe,sye,eatf
DIM movelist(600,3) : REM 1 : Start Square 2 : Dest Square 3 : Points
mlp = 0 : REM MoveListPointer (Reset)
FOR xp = 1 TO 8
FOR yp = 1 TO 8
checksquare xp,yp,a
IF a THEN
p = a(xp,yp)
IF p<>0 THEN
pf= p/ABS(p)
ELSE
pf= 0
END IF
IF pf = col THEN
INCR mlp
movelist(mlp,1) = xp + ((yp-1)*8)
END IF
END IF
NEXT yp
NEXT xp
REM ----------------------------------- Get First Move
bflg = 0
LOCATE 57,1:PRINT "----------------------------------------------------------------------":scrlmsg
FOR xk1 = 1 TO mlp
ps = movelist(xk1,1)
yp = INT((ps-1)/8)
xp = ps-(yp*8)
INCR yp
flg1 = 0
getmoves a(),xp,yp,xn,yn,flg1
IF flg1 > bflg THEN
bflg = flg1
sx = xp
sy = yp
dx = xn
dy = yn
LOCATE 57,1:PRINT "CHK1",sx,sy,dx,dy :scrlmsg
unsafe = -1
END IF
IF flg1 >= bflg AND NOT(eatf) AND unsafe = -1
bflg = flg1
sx = xp
sy = yp
dx = xn
dy = yn
unsafe = 0
LOCATE 57,1:PRINT "SAFE",sx,sy,dx,dy :scrlmsg
END IF
IF flg1 = bflg AND (RND>0.7) AND NOT(eatf) THEN
bflg = flg1
sx = xp
sy = yp
dx = xn
dy = yn
unsafe = 0
LOCATE 57,1:PRINT "RAND",sx,sy,dx,dy :scrlmsg
END IF
NEXT xk1
REM ------------------------------------ Execute the Move
FOR x = 1 TO 8
FOR y = 1 TO 8
n(x,y) = a(x,y)
NEXT y
NEXT x
PALETTE 0,0,0,0
IF bflg = 0 THEN
PALETTE 0,0,0,1
END IF
IF bflg < 0 THEN
PALETTE 0,1,0,0
END IF
IF bflg > 0 THEN
mark sx,sy,sxs,sys,sxe,sye
mark dx,dy,sxs,sys,sxe,sye
SWAP n(sx,sy),n(dx,dy)
END IF
IF bflg = 2 THEN
kx = ((dx-sx)/2)+sx
ky = ((dy-sy)/2)+sy
n(kx,ky) = 0
END IF
REM ------------------------------------- Second Eat Move
IF bflg = 2 THEN
nxtmove:
flg1 = 1
getmoves n(),dx,dy,nx,ny,flg1
IF flg1 = 2 THEN
mark nx,ny,sxs,sys,sxe,sye
SWAP n(nx,ny),n(dx,dy)
kx = ((nx-dx)/2)+dx
ky = ((ny-dy)/2)+dy
n(kx,ky) = 0
dx = nx : dy = ny
GOTO nxtmove
END IF
END IF
FOR x = 1 TO 8
FOR y = 1 TO 8
a(x,y) = n(x,y)
NEXT y
NEXT x
ERASE movelist
END SUB
REM --------------------------------- TEST LOOKAHEAD
SUB test(a(),col,n()) STATIC
SHARED sxs,sys,sxe,sye
DIM movelist2(600,3) : REM 1 : Start Square 2 : Dest Square 3 : Points
mlp2 = 0 : REM movelist2Pointer (Reset)
FOR xp = 1 TO 8
FOR yp = 1 TO 8
checksquare xp,yp,a
IF a THEN
p = a(xp,yp)
IF p<>0 THEN
pf= p/ABS(p)
ELSE
pf= 0
END IF
IF pf = col THEN
INCR mlp2
movelist2(mlp2,1) = xp + ((yp-1)*8)
END IF
END IF
NEXT yp
NEXT xp
REM ----------------------------------- Get First Move
bflt = 0
FOR xk1 = 1 TO mlp2
ps = movelist2(xk1,1)
yp = INT((ps-1)/8)
xp = ps-(yp*8)
INCR yp
flg1 = 0
getmoves a(),xp,yp,xn,yn,flg1
IF flg1 > bflt THEN
bflt = flg1
sx = xp
sy = yp
dx = xn
dy = yn
END IF
NEXT xk1
REM ------------------------------------ Execute the Move
FOR x = 1 TO 8
FOR y = 1 TO 8
n(x,y) = a(x,y)
NEXT y
NEXT x
PALETTE 0,0,0,0
IF bflt = 0 THEN
PALETTE 0,0,0,1
END IF
IF bflt < 0 THEN
PALETTE 0,1,0,0
END IF
IF bflt > 0 THEN
mark sx,sy,sxs,sys,sxe,sye
mark dx,dy,sxs,sys,sxe,sye
SWAP n(sx,sy),n(dx,dy)
END IF
IF bflt = 2 THEN
kx = ((dx-sx)/2)+sx
ky = ((dy-sy)/2)+sy
n(kx,ky) = 0
END IF
REM ------------------------------------- Second Eat Move
IF bflt = 2 THEN
nxtmove2:
flg1 = 1
getmoves n(),dx,dy,nx,ny,flg1
IF flg1 = 2 THEN
mark nx,ny,sxs,sys,sxe,sye
SWAP n(nx,ny),n(dx,dy)
kx = ((nx-dx)/2)+dx
ky = ((ny-dy)/2)+dy
n(kx,ky) = 0
dx = nx : dy = ny
GOTO nxtmove2
END IF
END IF
' FOR x = 1 TO 8
' FOR y = 1 TO 8
' a(x,y) = n(x,y)
' NEXT y
' NEXT x
ERASE movelist2
END SUB
SUB makekings(a(),flag) STATIC
FOR x = 1 TO 8
p1 = a(x,1)
p2 = a(x,8)
IF flag AND p1=1 THEN a(x,1) = 2
IF NOT(flag) AND p1=-1 THEN a(x,1) = -2
IF flag AND p2=-1 THEN a(x,8) = -2
IF NOT(flag) AND p2=1 THEN a(x,8) = 2
NEXT x
END SUB
SUB getmoves(a(),x,y,x1,y1,flags) STATIC
REM -- FLAGS = 1 on Entry := Non-Eat moves discarded
LOCAL ur,dr,ul,dl,p
LOCAL urp,drp,ulp,dlp
SHARED eatf
ur = -1 : dr = -1 : ul = -1 : dl = -1 : REM UpRight ...
p = a(x,y)
REM ------------------------- Eliminate Non-King Non-Moves
IF ABS(p) = 1 THEN
IF p = 1 THEN ur = 0 : ul = 0
IF p = -1 THEN dr= 0 : dl = 0
END IF
REM ------------------------- Board Edge Check
IF x = 8 THEN ur = 0 : dr = 0
IF x = 1 THEN ul = 0 : dl = 0
IF y = 8 THEN dr = 0 : dl = 0
IF y = 1 THEN ur = 0 : ul = 0
REM ------------------------- Check if friendly pieces in way
IF ur THEN p = a(x+1,y-1) : IF p/a(x,y) > 0 THEN ur = 0
IF ul THEN p = a(x-1,y-1) : IF p/a(x,y) > 0 THEN ul = 0
IF dr THEN p = a(x+1,y+1) : IF p/a(x,y) > 0 THEN dr = 0
IF dl THEN p = a(x-1,y+1) : IF p/a(x,y) > 0 THEN dl = 0
REM -------------------------- Eliminate non-eat moves
IF flags = 1 THEN
IF ur THEN p = a(x+1,y-1) : IF p = 0 THEN ur = 0
IF ul THEN p = a(x-1,y-1) : IF p = 0 THEN ul = 0
IF dr THEN p = a(x+1,y+1) : IF p = 0 THEN dr = 0
IF dl THEN p = a(x-1,y+1) : IF p = 0 THEN dl = 0
END IF
REM -------------------------- Initialise Move Pointers
urp = 0 : ulp = 0 : drp = 0 : dlp = 0
REM -------------------------- Check if step-moves are possible
IF ur THEN p = a(x+1,y-1) : IF p = 0 THEN urp = 1 : ur = 0
IF ul THEN p = a(x-1,y-1) : IF p = 0 THEN ulp = 1 : ul = 0
IF dr THEN p = a(x+1,y+1) : IF p = 0 THEN drp = 1 : dr = 0
IF dl THEN p = a(x-1,y+1) : IF p = 0 THEN dlp = 1 : dl = 0
REM -------------------------- Select Best step-Move ..
IF testing THEN GOTO skipTEST
testing = -1
DIM tar(8,8),tar2(8,8),tar3(8,8),tar4(8,8)
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
cl = a(x,y)/ABS(a(x,y))
ncl = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
ncl = ncl + a(xt,yt)
NEXT yt
NEXT xt
ncl = ncl * cl
ldiff = -100
IF urp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+1,y-1)
test tar(),cl,tar4()
makekings tar4(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN ldiff=diff
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF ulp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-1,y-1)
test tar(),cl,tar4()
makekings tar4(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN
ldiff=diff
urp = 0
ELSE
ulp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF drp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+1,y+1)
test tar(),cl,tar4()
makekings tar4(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN
ldiff=diff
urp = 0
ulp = 0
ELSE
drp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF dlp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-1,y+1)
test tar(),cl,tar4()
makekings tar4(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN
ldiff=diff
urp = 0
ulp = 0
drp = 0
ELSE
dlp = 0
END IF
END IF
IF ldiff > 0 THEN eatf = 0 ELSE eatf = -1
ERASE tar,tar2,tar3,tar4
testing = 0
skiptest:
REM -------------------------- Check if eat-moves are possible
IF x = 7 THEN ur = 0 : dr = 0
IF x = 2 THEN ul = 0 : dl = 0
IF y = 7 THEN dr = 0 : dl = 0
IF y = 2 THEN ur = 0 : ul = 0
em = 0 : REM -- No Eat Move (Yet)
IF ur THEN p = a(x+2,y-2) : IF p = 0 THEN urp = 2 : em = -1
IF ul THEN p = a(x-2,y-2) : IF p = 0 THEN ulp = 2 : em = -1
IF dr THEN p = a(x+2,y+2) : IF p = 0 THEN drp = 2 : em = -1
IF dl THEN p = a(x-2,y+2) : IF p = 0 THEN dlp = 2 : em = -1
REM -------------------------- If Eat if possible , no step-moves
IF em THEN
IF urp < 2 THEN urp = 0
IF ulp < 2 THEN ulp = 0
IF drp < 2 THEN drp = 0
IF dlp < 2 THEN dlp = 0
END IF
REM -------------------------- Select B E S T Move
IF testing THEN GOTO skipSBME
testing = -1
DIM tar(8,8),tar2(8,8),tar3(8,8),tar4(8,8)
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
cl = a(x,y)/ABS(a(x,y))
ncl = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
ncl = ncl + a(xt,yt)
NEXT yt
NEXT xt
ncl = ncl * cl
ldiff = -100
IF urp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+2,y-2)
tar(x+1,y-1) = 0
test tar(),cl,tar4()
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN ldiff=diff
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF ulp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-2,y-2)
tar(x-1,y-1) = 0
test tar(),cl,tar4()
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN
ldiff=diff
urp = 0
ELSE
ulp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF drp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+2,y+2)
tar(x+1,y+1) = 0
test tar(),cl,tar4()
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN
ldiff=diff
urp = 0
ulp = 0
ELSE
drp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF dlp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-2,y+2)
tar(x-1,y+1) = 0
test tar(),cl,tar4()
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar4(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
IF diff => 0 THEN
test tar4(),-cl,tar3()
test tar3(),cl,tar2()
makekings tar2(),0
nclt = 0
FOR xt = 1 TO 8
FOR yt = 1 TO 8
nclt = nclt + tar2(xt,yt)
NEXT yt
NEXT xt
nclt = nclt * (-cl)
diff = nclt-ncl
END IF
IF diff>ldiff THEN
ldiff=diff
urp = 0
ulp = 0
drp = 0
ELSE
dlp = 0
END IF
END IF
IF em THEN
IF ldiff > 0 THEN eatf = 0 ELSE eatf = -1
END IF
ERASE tar,tar2,tar3,tar4
testing = 0
skipSBME:
xd = 0 : yd = 0 : mrp = 0
IF urp > mrp THEN xd = 1 : yd = -1 : mrp = urp
IF ulp > mrp THEN xd = -1 : yd = -1 : mrp = ulp
IF drp > mrp THEN xd = 1 : yd = 1 : mrp = drp
IF dlp > mrp THEN xd = -1 : yd = 1 : mrp = dlp
IF mrp = 2 THEN
xd = xd * 2 : yd = yd * 2
END IF
REM -------------------------- Set Output Variables
x1 = x + xd
y1 = y + yd
flags = mrp
END SUB
REM ----------------------------------------- SCREEN UPDATE ROUTINE
SUB mark(xp,yp,x,y,xl,yl) STATIC
EXIT SUB
sx = (xl/8)*(xp-1)
ex = sx + xl/8
sy = (yl/8)*(yp-1)
ey = sy + yl/8
sx = sx + x
sy = sy + y
ex = ex + x
ey = ey + y
FOR n = 1 TO 3
FOR c = 0 TO 1
LINE (sx+c,sy+c)-(ex-c,ey-c),3,b
NEXT c
FOR c = 0 TO 1
LINE (sx+c,sy+c)-(ex-c,ey-c),2,b
NEXT c
FOR c = 0 TO 1
LINE (sx+c,sy+c)-(ex-c,ey-c),1,b
NEXT c
FOR c = 0 TO 1
LINE (sx+c,sy+c)-(ex-c,ey-c),0,b
NEXT c
NEXT n
END SUB
SUB update(a(),x,y,xl,yl) STATIC
IF NOT(fgUD) THEN
DIM bb(8,8)
FOR xbb = 1 TO 8 : FOR ybb = 1 TO 8
bb(xbb,ybb) = 30
NEXT ybb : NEXT xbb
fgUD = -1
END IF
rk=0:rp=0:bk=0:bp=0
FOR xp = 1 TO 8
FOR yp = 1 TO 8
IF a(xp,yp) = -1 THEN INCR rp
IF a(xp,yp) = -2 THEN INCR rk
IF a(xp,yp) = 1 THEN INCR bp
IF a(xp,yp) = 2 THEN INCR bk
IF a(xp,yp) = bb(xp,yp) THEN GOTO skip1
bb(xp,yp) = a(xp,yp)
sx = (xl/8)*(xp-1)
ex = sx + xl/8
sy = (yl/8)*(yp-1)
ey = sy + yl/8
sx = sx + x
sy = sy + y
ex = ex + x
ey = ey + y
cl = ((xp+yp)/2) - INT((xp+yp)/2)
IF cl = 0 THEN
colr = 0
ELSE
colr = 1
END IF
LINE (sx,sy)-(ex,ey),colr,bf
IF a(xp,yp) < 0 THEN
sx = sx + (xl/16)
sy = sy + (yl/16)
rd = SQR(((yl/20)^2)+((xl/20)^2))
rd = rd / 1.3
CIRCLE (sx,sy),rd,2,,,yl/xl
PAINT (sx,sy),2
IF a(xp,yp) = -2 THEN
FOR xx = rd*4/5 TO rd
CIRCLE (sx,sy),xx,1,,,yl/xl
NEXT xx
END IF
END IF
IF a(xp,yp) > 0 THEN
sx = sx + (xl/16)
sy = sy + (yl/16)
rd = SQR(((yl/20)^2)+((xl/20)^2))
rd = rd / 1.3
CIRCLE (sx,sy),rd,3,,,yl/xl
PAINT (sx,sy),3
IF a(xp,yp) = 2 THEN
FOR xx = rd*4/5 TO rd
CIRCLE (sx,sy),xx,1,,,yl/xl
NEXT xx
END IF
END IF
skip1:
NEXT yp
NEXT xp
sx = INT((x/8)+2)
sy = INT((yl*7/64)+(y/8)+2)
COLOR 0,1
LOCATE sy+0,sx+0 : PRINT "Cl K P"
LOCATE sy+1,sx : PRINT "Rd";
LOCATE sy+1,sx+2 : PRINT rk;
LOCATE sy+1,sx+5 : PRINT rp;
LOCATE sy+2,sx : PRINT "Bl";
LOCATE sy+2,sx+2 : PRINT bk;
LOCATE sy+2,sx+5 : PRINT bp;
COLOR 1,0
END SUB
SUB setpieces(a()) STATIC
FOR y = 1 TO 3
FOR x = 1 TO 8
checksquare x,y,a
IF a THEN a(x,y) = 1 ELSE a(x,y) =0
NEXT x
NEXT y
FOR y = 4 TO 5
FOR x = 1 TO 8
checksquare x,y,a
IF a THEN a(x,y) = 0 ELSE a(x,y) =0
NEXT x
NEXT y
FOR y = 6 TO 8
FOR x = 1 TO 8
checksquare x,y,a
IF a THEN a(x,y) = -1 ELSE a(x,y) =0
NEXT x
NEXT y
END SUB
SUB scrlmsg STATIC
SHARED sye
SCROLL (0,sye+1)-(600,480),0,-2
SCROLL (0,sye+1)-(600,480),0,-2
SCROLL (0,sye+1)-(600,480),0,-2
SCROLL (0,sye+1)-(600,480),0,-3
IF INKEY$ <> "" THEN
LOCATE 58,70 : PRINT "PAUSE"
WHILE INKEY$ = "" : WEND
LOCATE 58,70 : PRINT " "
END IF
END SUB
SUB checksquare(xp,yp,a) STATIC
cl = ((xp+yp)/2) - INT((xp+yp)/2)
IF cl = 0 THEN
a = -1
ELSE
a = 0
END IF
END SUB
REM --------------------------------------------------------------------
REM ---- THIS IS THE OPPONENT THAT MUST BE WON ** WITH REGULARITY ** ---
REM --------------------------------------------------------------------
SUB play2(a(),col,n()) STATIC
SHARED sxs,sys,sxe,sye,eatf
DIM movelist(600,3) : REM 1 : Start Square 2 : Dest Square 3 : Points
mlp = 0 : REM MoveListPointer (Reset)
FOR xp = 1 TO 8
FOR yp = 1 TO 8
checksquare xp,yp,a
IF a THEN
p = a(xp,yp)
IF p<>0 THEN
pf= p/ABS(p)
ELSE
pf= 0
END IF
IF pf = col THEN
INCR mlp
movelist(mlp,1) = xp + ((yp-1)*8)
END IF
END IF
NEXT yp
NEXT xp
REM ----------------------------------- Get First Move
bflg = 0
LOCATE 57,1:PRINT "----------------------------------------------------------------------":scrlmsg
FOR xk1 = 1 TO mlp
ps = movelist(xk1,1)
yp = INT((ps-1)/8)
xp = ps-(yp*8)
INCR yp
flg1 = 0
getmoves2 a(),xp,yp,xn,yn,flg1
IF flg1 > bflg THEN
bflg = flg1
sx = xp
sy = yp
dx = xn
dy = yn
LOCATE 57,1:PRINT "CHK1",sx,sy,dx,dy :scrlmsg
unsafe = -1
END IF
IF flg1 >= bflg AND NOT(eatf) AND unsafe = -1
bflg = flg1
sx = xp
sy = yp
dx = xn
dy = yn
unsafe = 0
LOCATE 57,1:PRINT "SAFE",sx,sy,dx,dy :scrlmsg
END IF
IF flg1 = bflg AND (RND>0.7) AND NOT(eatf) THEN
bflg = flg1
sx = xp
sy = yp
dx = xn
dy = yn
unsafe = 0
LOCATE 57,1:PRINT "RAND",sx,sy,dx,dy :scrlmsg
END IF
NEXT xk1
REM ------------------------------------ Execute the Move
FOR x = 1 TO 8
FOR y = 1 TO 8
n(x,y) = a(x,y)
NEXT y
NEXT x
PALETTE 0,0,0,0
IF bflg = 0 THEN
PALETTE 0,0,0,1
END IF
IF bflg < 0 THEN
PALETTE 0,1,0,0
END IF
IF bflg > 0 THEN
mark sx,sy,sxs,sys,sxe,sye
mark dx,dy,sxs,sys,sxe,sye
SWAP n(sx,sy),n(dx,dy)
END IF
IF bflg = 2 THEN
kx = ((dx-sx)/2)+sx
ky = ((dy-sy)/2)+sy
n(kx,ky) = 0
END IF
REM ------------------------------------- Second Eat Move
IF bflg = 2 THEN
nxtmove3:
flg1 = 1
getmoves2 n(),dx,dy,nx,ny,flg1
IF flg1 = 2 THEN
mark nx,ny,sxs,sys,sxe,sye
SWAP n(nx,ny),n(dx,dy)
kx = ((nx-dx)/2)+dx
ky = ((ny-dy)/2)+dy
n(kx,ky) = 0
dx = nx : dy = ny
GOTO nxtmove3
END IF
END IF
FOR x = 1 TO 8
FOR y = 1 TO 8
a(x,y) = n(x,y)
NEXT y
NEXT x
ERASE movelist
END SUB
SUB getmoves2(a(),x,y,x1,y1,flags) STATIC
REM -- FLAGS = 1 on Entry := Non-Eat moves discarded
LOCAL ur,dr,ul,dl,p
LOCAL urp,drp,ulp,dlp
SHARED eatf
ur = -1 : dr = -1 : ul = -1 : dl = -1 : REM UpRight ...
p = a(x,y)
REM ------------------------- Eliminate Non-King Non-Moves
IF ABS(p) = 1 THEN
IF p = 1 THEN ur = 0 : ul = 0
IF p = -1 THEN dr= 0 : dl = 0
END IF
REM ------------------------- Board Edge Check
IF x = 8 THEN ur = 0 : dr = 0
IF x = 1 THEN ul = 0 : dl = 0
IF y = 8 THEN dr = 0 : dl = 0
IF y = 1 THEN ur = 0 : ul = 0
REM ------------------------- Check if friendly pieces in way
IF ur THEN p = a(x+1,y-1) : IF p/a(x,y) > 0 THEN ur = 0
IF ul THEN p = a(x-1,y-1) : IF p/a(x,y) > 0 THEN ul = 0
IF dr THEN p = a(x+1,y+1) : IF p/a(x,y) > 0 THEN dr = 0
IF dl THEN p = a(x-1,y+1) : IF p/a(x,y) > 0 THEN dl = 0
REM -------------------------- Eliminate non-eat moves
IF flags = 1 THEN
IF ur THEN p = a(x+1,y-1) : IF p = 0 THEN ur = 0
IF ul THEN p = a(x-1,y-1) : IF p = 0 THEN ul = 0
IF dr THEN p = a(x+1,y+1) : IF p = 0 THEN dr = 0
IF dl THEN p = a(x-1,y+1) : IF p = 0 THEN dl = 0
END IF
REM -------------------------- Initialise Move Pointers
urp = 0 : ulp = 0 : drp = 0 : dlp = 0
REM -------------------------- Check if step-moves are possible
IF ur THEN p = a(x+1,y-1) : IF p = 0 THEN urp = 1 : ur = 0
IF ul THEN p = a(x-1,y-1) : IF p = 0 THEN ulp = 1 : ul = 0
IF dr THEN p = a(x+1,y+1) : IF p = 0 THEN drp = 1 : dr = 0
IF dl THEN p = a(x-1,y+1) : IF p = 0 THEN dlp = 1 : dl = 0
REM -------------------------- Select Best step-Move ..
IF testing THEN GOTO skipTEST2
testing = -1
DIM tar(8,8),tar2(8,8)
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
cl = a(x,y)/ABS(a(x,y))
ncl = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF a(xt,yt) <> 0 THEN
IF a(xt,yt)/ABS(a(xt,yt)) = cl THEN
ncl = ncl + a(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
ncl = ABS(ncl)
ldiff = 10
IF urp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+1,y-1)
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN ldiff=diff
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF ulp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-1,y-1)
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN
ldiff=diff
urp = 0
ELSE
ulp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF drp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+1,y+1)
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN
ldiff=diff
urp = 0
ulp = 0
ELSE
drp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF dlp = 1 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-1,y+1)
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN
ldiff=diff
urp = 0
ulp = 0
drp = 0
ELSE
dlp = 0
END IF
END IF
IF ldiff = 0 THEN eatf = 0 ELSE eatf = -1
IF ldiff < 0 THEN PALETTE 0,1,0,0
ERASE tar,tar2
testing = 0
skiptest2:
REM -------------------------- Check if eat-moves are possible
IF x = 7 THEN ur = 0 : dr = 0
IF x = 2 THEN ul = 0 : dl = 0
IF y = 7 THEN dr = 0 : dl = 0
IF y = 2 THEN ur = 0 : ul = 0
em = 0 : REM -- No Eat Move (Yet)
IF ur THEN p = a(x+2,y-2) : IF p = 0 THEN urp = 2 : em = -1
IF ul THEN p = a(x-2,y-2) : IF p = 0 THEN ulp = 2 : em = -1
IF dr THEN p = a(x+2,y+2) : IF p = 0 THEN drp = 2 : em = -1
IF dl THEN p = a(x-2,y+2) : IF p = 0 THEN dlp = 2 : em = -1
REM -------------------------- If Eat if possible , no step-moves
IF em THEN
IF urp < 2 THEN urp = 0
IF ulp < 2 THEN ulp = 0
IF drp < 2 THEN drp = 0
IF dlp < 2 THEN dlp = 0
END IF
REM -------------------------- Select B E S T Move
IF testing THEN GOTO skipSBME2
testing = -1
DIM tar(8,8),tar2(8,8)
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
cl = a(x,y)/ABS(a(x,y))
ncl = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF a(xt,yt) <> 0 THEN
IF a(xt,yt)/ABS(a(xt,yt)) = cl THEN
ncl = ncl + a(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
ncl = ABS(ncl)
ldiff = 1000
IF urp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+2,y-2)
tar(x+1,y-1) = 0
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN ldiff=diff
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF ulp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-2,y-2)
tar(x-1,y-1) = 0
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN
ldiff=diff
urp = 0
ELSE
ulp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF drp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x+2,y+2)
tar(x+1,y+1) = 0
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN
ldiff=diff
urp = 0
ulp = 0
ELSE
drp = 0
END IF
END IF
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
tar(xt,yt) = a(xt,yt)
NEXT yt : NEXT xt
IF dlp = 2 THEN
cl = a(x,y)/ABS(a(x,y))
cl = cl * -1
SWAP tar(x,y),tar(x-2,y+2)
tar(x-1,y+1) = 0
test22 tar(),cl,tar2()
nclt = 0
FOR xt = 1 TO 8 : FOR yt = 1 TO 8
IF tar2(xt,yt) <> 0 THEN
IF tar2(xt,yt)/ABS(tar2(xt,yt)) = -cl THEN
nclt = nclt + tar2(xt,yt)
END IF
END IF
NEXT yt : NEXT xt
nclt = ABS(nclt)
diff = ncl-nclt
IF diff<ldiff THEN
ldiff=diff
urp = 0
ulp = 0
drp = 0
ELSE
dlp = 0
END IF
END IF
IF em THEN
IF ldiff = 0 THEN eatf = 0 ELSE eatf = -1
IF ldiff < 0 THEN PALETTE 0,1,0,0
END IF
ERASE tar,tar2
testing = 0
skipSBME2:
xd = 0 : yd = 0 : mrp = 0
IF urp > mrp THEN xd = 1 : yd = -1 : mrp = urp
IF ulp > mrp THEN xd = -1 : yd = -1 : mrp = ulp
IF drp > mrp THEN xd = 1 : yd = 1 : mrp = drp
IF dlp > mrp THEN xd = -1 : yd = 1 : mrp = dlp
IF mrp = 2 THEN
xd = xd * 2 : yd = yd * 2
END IF
REM -------------------------- Set Output Variables
x1 = x + xd
y1 = y + yd
flags = mrp
END SUB
SUB test22(a(),col,n()) STATIC
SHARED sxs,sys,sxe,sye
DIM movelist22(600,3) : REM 1 : Start Square 2 : Dest Square 3 : Points
mlp2 = 0 : REM movelist22Pointer (Reset)
FOR xp = 1 TO 8
FOR yp = 1 TO 8
checksquare xp,yp,a
IF a THEN
p = a(xp,yp)
IF p<>0 THEN
pf= p/ABS(p)
ELSE
pf= 0
END IF
IF pf = col THEN
INCR mlp2
movelist22(mlp2,1) = xp + ((yp-1)*8)
END IF
END IF
NEXT yp
NEXT xp
REM ----------------------------------- Get First Move
bflt = 0
FOR xk1 = 1 TO mlp2
ps = movelist22(xk1,1)
yp = INT((ps-1)/8)
xp = ps-(yp*8)
INCR yp
flg1 = 0
getmoves2 a(),xp,yp,xn,yn,flg1
IF flg1 > bflt THEN
bflt = flg1
sx = xp
sy = yp
dx = xn
dy = yn
END IF
NEXT xk1
REM ------------------------------------ Execute the Move
FOR x = 1 TO 8
FOR y = 1 TO 8
n(x,y) = a(x,y)
NEXT y
NEXT x
PALETTE 0,0,0,0
IF bflt = 0 THEN
PALETTE 0,0,0,1
END IF
IF bflt < 0 THEN
PALETTE 0,1,0,0
END IF
IF bflt > 0 THEN
mark sx,sy,sxs,sys,sxe,sye
mark dx,dy,sxs,sys,sxe,sye
SWAP n(sx,sy),n(dx,dy)
END IF
IF bflt = 2 THEN
kx = ((dx-sx)/2)+sx
ky = ((dy-sy)/2)+sy
n(kx,ky) = 0
END IF
REM ------------------------------------- Second Eat Move
IF bflt = 2 THEN
nxtmove22:
flg1 = 1
getmoves2 n(),dx,dy,nx,ny,flg1
IF flg1 = 2 THEN
mark nx,ny,sxs,sys,sxe,sye
SWAP n(nx,ny),n(dx,dy)
kx = ((nx-dx)/2)+dx
ky = ((ny-dy)/2)+dy
n(kx,ky) = 0
dx = nx : dy = ny
GOTO nxtmove22
END IF
END IF
FOR x = 1 TO 8
FOR y = 1 TO 8
a(x,y) = n(x,y)
NEXT y
NEXT x
ERASE movelist22
END SUB